package signGrammar.view;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;

import signGrammar.expressions.IGrammarExpression;

public class CViewNonterminalChoiceButton extends JButton {
	private static final long serialVersionUID = 6067525714771182355L;

	public interface INonterminalChoiceListener {
		public void nonterminalChoise(String nameID, IGrammarExpression expression);
	}
	
	public static class CNonterminalChoiceListenerAdapter implements ActionListener {
		private INonterminalChoiceListener variableListener;
		private IGrammarExpression expression;
		public CNonterminalChoiceListenerAdapter(IGrammarExpression e, INonterminalChoiceListener variableListener) {
			this.variableListener = variableListener;
			this.expression       = e;
		}
		@Override public void actionPerformed(ActionEvent e) {
			variableListener.nonterminalChoise( e.getActionCommand(), expression);
		}		
	}
	
	public CViewNonterminalChoiceButton(String nameID, IGrammarExpression e, INonterminalChoiceListener listener) {
		setText( e.toString() );
		setActionCommand( nameID );
		addActionListener( new CNonterminalChoiceListenerAdapter(e, listener ) );
	}
}
